﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Gueei.Gallery.Security
{
	[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
	public class AuthorizeToEditAttribute : FilterAttribute, IActionFilter
	{
		public void OnActionExecuted(ActionExecutedContext filterContext)
		{
		}

		public void OnActionExecuting(ActionExecutingContext filterContext)
		{
			if (filterContext.HttpContext.User.IsInRole(GalleryRoles.EditImage))
			{
				filterContext.ActionParameters["editMode"] = true;
			}
			else
				filterContext.ActionParameters["editMode"] = false;
		}
	}
}
